package com.woniuxy.cloud.userassembly.mapper;

import com.woniuxy.cloud.userassembly.entity.SysResource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 周川雄
 * @since 2022-01-26
 */
public interface SysResourceMapper extends BaseMapper<SysResource> {
    @Select("SELECT\n" +
            "\tt4.resources_uri\n" +
            "FROM\n" +
            "\tuser_role t1\n" +
            "JOIN `user` t2 ON t1.user_id = t2.user_id\n" +
            "JOIN `role_resources` t3 ON t3.role_id = t1.role_id\n" +
            "JOIN sys_resource t4 ON t4.resources_id = t3.resources_id\n" +
            "WHERE\n" +
            "\tt2.user_id = #{id}\n" +
            "UNION\n" +
            "\tSELECT\n" +
            "\t\tresources_uri\n" +
            "\tFROM\n" +
            "\t\tsys_resource\n" +
            "\tWHERE\n" +
            "\t\tresources_state = 0")
    List<String> selectResourceByUserId(Integer id);
}
